package
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	[SWF(width = "800", height = "600", backgroundColor = "0x66ccff", frameRate="60")]
	public class Test3d extends Sprite
	{

		private var treeArr:Array = [];
		private var n:Number = 0;
		
		public function Test3d()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener(Event.RESIZE,onResize);
			stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
			
			for (var i:int = 0; i < 100; i++) 
			{
				var tree:Tree = new Tree();
				tree.x=Math.random()*stage.stageWidth;
				tree.y=stage.stageHeight - 100;
				tree.z=Math.random()*4000;
				addChild(tree);
				treeArr.push(tree);
			}
			treeArr.sortOn("z",Array.NUMERIC);
			for (var j:int=0; j<treeArr.length; j++) 
			{
				setChildIndex(treeArr[j] as Tree,0);
			}
		}
		
		protected function onMove(event:MouseEvent):void
		{
			root.transform.perspectiveProjection.projectionCenter = new Point(mouseX,mouseY);
		}
		
		protected function onResize(event:Event):void
		{
			//root.transform.perspectiveProjection.projectionCenter = new Point(stage.stageWidth/2,stage.stageHeight/2);
		}
	}
}